package vue;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;

import modele.Element;


public class VueElement {
    
    private Element element;
    private VueCadre vueCadre;
    private int width;
    private int height;
    private boolean selected;


    public VueElement(Element element, VueCadre vueCadre, int width, int height) {
        super();
        this.element = element;
        this.vueCadre = vueCadre;
        this.width = width;
        this.height = height;
        this.selected=false;
    }

    public VueElement() {
        super();
    }


    public void Dessiner(Graphics g) {
        Color c = g.getColor();
        Color d;
        if(selected==true) {
            d = new Color(0,0,100);
        }
        else {
            d = new Color(0,100,0);
        }
        g.setColor(d);
        Point p_pixel = vueCadre.ConvertirEnPixel(element.GetCoordonnees());
        g.fillRect((int)(p_pixel.getX()-width/2), (int)p_pixel.getY()-height/2, width, height);
        g.setColor(c);
    }
    
    public boolean isClicked (int x, int y) {
        Point p_pixel = vueCadre.ConvertirEnPixel(element.GetCoordonnees());
        
        return ((p_pixel.getX() - width/2 < x) && (p_pixel.getX() + width/2 > x)
            && (p_pixel.getY() - height/2 < y) && (p_pixel.getY() + height/2 > y));
    }
    

    public Element getElement() {
        return element;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getWidth() {
        return width;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getHeight() {
        return height;
    }

    public void setElement(Element element) {
        this.element = element;
    }

    public boolean getSelected() {
        return selected;
    }

    public void setSelected(boolean selected) {
        this.selected = selected;
    }

    public VueCadre getVueCadre() {
        return vueCadre;
    }

    public void setVueCadre(VueCadre vueCadre) {
        this.vueCadre = vueCadre;
    }
}
